const http = require('http');
const fs = require('fs');

let user = { id: 1, name: 'Jimmy' };

const app = new http.createServer((req, res) => {
  res.setHeader('Access-Control-Allow-Origin', '*');
  // if(req.url.startsWith(''))
  console.log(req.url);
  let url = req.url;
  if (url === '/base') {
    res.end(JSON.stringify(user));
  } else if (url === '/about?user=Jimmy') {
    res.end('JimmyMsg');
  } else if (url === '/detail?msg=JimmyMsg') {
    let docs = fs.readFileSync('./JimmyMsg.txt', { encoding: 'utf-8' });
    res.end(docs);
  }
});

app.listen(666);
